From: Keir Fraser Date: Mon, 11 Feb 2008 09:45:36 +0000 (+0000) Subject: xentrace: Fix bug in logic for bytes_to_wrap in trace buffer. X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~14317^2~63 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https:/%22bookmarks:/%22man:///%22http:/www.example.com/cgi/%22https:/%22bookmarks:/%22man:/?a=commitdiff_plain;h=4be9201e8c34104b15ac2eda6b8c3092d7baa191;p=xen.git xentrace: Fix bug in logic for bytes_to_wrap in trace buffer. Admittedly, the bug could only be manifest with much larger trace records than are currently allowed (or equivalently, much smaller trace buffers), but the old code was harder to read, and thus hid the logic bug well, too. Signed-off-by: Michael A Fetterman --- diff --git a/xen/common/trace.c b/xen/common/trace.c index 9af70798bb..d2f8fceeae 100644 --- a/xen/common/trace.c +++ b/xen/common/trace.c @@ -425,25 +425,18 @@ void __trace_var(u32 event, int cycles, int extra, unsigned char *extra_data) total_size += bytes_to_wrap; bytes_to_wrap = data_size; } - else - { - bytes_to_wrap -= LOST_REC_SIZE; - if ( bytes_to_wrap == 0 ) - bytes_to_wrap = data_size; - } total_size += LOST_REC_SIZE; + bytes_to_wrap -= LOST_REC_SIZE; + + /* LOST_REC might line up perfectly with the buffer wrap */ + if ( bytes_to_wrap == 0 ) + bytes_to_wrap = data_size; } if ( rec_size > bytes_to_wrap ) { total_size += bytes_to_wrap; - bytes_to_wrap = data_size; } - else - { - bytes_to_wrap -= rec_size; - } - total_size += rec_size; /* Do we have enough space for everything? */ @@ -466,14 +459,12 @@ void __trace_var(u32 event, int cycles, int extra, unsigned char *extra_data) insert_wrap_record(buf, LOST_REC_SIZE); bytes_to_wrap = data_size; } - else - { - bytes_to_wrap -= LOST_REC_SIZE; - /* LOST_REC might line up perfectly with the buffer wrap */ - if ( bytes_to_wrap == 0 ) - bytes_to_wrap = data_size; - } insert_lost_records(buf); + bytes_to_wrap -= LOST_REC_SIZE; + + /* LOST_REC might line up perfectly with the buffer wrap */ + if ( bytes_to_wrap == 0 ) + bytes_to_wrap = data_size; } if ( rec_size > bytes_to_wrap )